<?php 
/**
 * 数据库备份管理控制器
 */
class BackupController extends AuthController{
	public function index(){
		$dirArr = Dir::tree('Backup');
		$this->assign('dirArr',$dirArr);
	    $this->display();
	}
	public function add(){
	    $result = Backup::backup(
	    array(
			'size'   =>    200,
			'dir'    =>   "Backup/" . date('ymdHis'),
			'step_time' => 1,
			)
		);
//		备份发生错误
		if($result === FALSE){
			$this->error(Backup::$error, U('Index/index'));
		}else{
//			如果备份成功
			if($result['status'] == 'success'){
				$this->success('备份成功',U('index'));
			}else{
				//备份过程中 
			 	$this->success($result['message'], $result['url'],0.1);
			}
		}
	}
	/**
	 * 还原
	 */
	public function recovery(){
		//备份目录 
		if(!isset($_SESSION['dir'])){
			$_SESSION['dir'] = Q('post.dir');
		}
		$result = Backup::recovery(array('dir' => $_SESSION['dir'])); 
		//还原发生错误
		if($result === false) {
			 $this->error(Backup::$error, U('index')); 
		}else{
			//还原完毕
			if($result['status'] == 'success'){
				unset($_SESSION['dir']);
				$this->success($result['message'], U('index'));
			}else{
				//还原过程中
				$this->success($result['message'], $result['url'], 0.1);
			}
		}
	}	
}
